#include <iostream>

using namespace std;
int has1[2];
int has2[2];
int main()
{
	int n;
	cin>>n;
	string num;
	cin>>num;
	int left=0,right=0;

	for(int i=0;i<n;i++)
	{
		has2[num[i]-'0']++;
	}
    // cout<<has2[0]<<' '<<has2[1]<<endl;
	int ret=0;
	int half=n/2;
	while(right<n-1)
	{
		has1[num[right]-'0']++;
        // cout<<has1[0]<<' '<<has1[1]<<endl;

		while(right-left+1>half)
		{
			has1[num[left]-'0']--;
			left++;
		}
		if(right-left+1==half && has1[0]*2==has2[0] && has1[1]*2==has2[1])
		{
			ret+=2;
		}
		right++;
		
	}
	cout<<ret<<endl;
	return 0;
}
